import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:open_source_china/constants/size_list.dart';
import 'package:open_source_china/pages/AboutPage/AboutPage.dart';
import 'package:open_source_china/pages/DynamicBlackHouse/DynamicBlackHouse.dart';
import 'package:open_source_china/pages/PublishDynamicPage/PublishDynamicPage.dart';
import 'package:open_source_china/pages/SettingsPage/SettingsPage.dart';

// 自定义抽屉
class MyDrawer extends StatelessWidget {
  final String avatarPath;
  final List<String> menuTitles;
  final List menuIcons;
  final String name;
  MyDrawer(
      {@required this.avatarPath,
      @required this.menuTitles,
      @required this.menuIcons,
      @required this.name})
      : assert(avatarPath != null),
        assert(menuTitles != null),
        assert(menuIcons != null);
  @override
  Widget build(BuildContext context) {
    // debugPaintSizeEnabled = true;
    return Drawer(
      child: Column(
        children: [
          Container(
            color: Colors.black45,
            height: 180.0,
            child: Row(
              children: [
                Expanded(
                  child: ListTile(
                    dense: true,
                    isThreeLine: true,
                    leading: Container(
                      width: SizeList.AVATAR_SIZE,
                      height: SizeList.AVATAR_SIZE,
                      child: avatarPath.contains("http")
                          ? Image.network(avatarPath, fit: BoxFit.fill)
                          : Image.asset(avatarPath, fit: BoxFit.fill),
                    ),
                    title: Text(
                      name,
                      style: TextStyle(fontSize: SizeList.FONT_SIZE_L),
                    ),
                    subtitle: Text("今天天气不错！"),
                  ),
                )
              ],
            ),
          ),
          Expanded(
            child: ListView.separated(
              itemCount: menuTitles.length,
              itemBuilder: (context, index) {
                return ListTile(
                  key: Key(index.toString()),
                  title: Text(menuTitles[index]),
                  leading: Icon(menuIcons[index]),
                  trailing: Icon(Icons.arrow_right),
                  onTap: () {
                    switch (index) {
                      case 0:
                        navPush(context, PublishDynamicPage());
                        break;
                      case 1:
                        navPush(context, DynamicBlackHouse());
                        break;
                      case 2:
                        navPush(context, AboutPage());
                        break;
                      case 3:
                        navPush(context, SettingsPage());
                        break;
                      default:
                    }
                  },
                );
              },
              separatorBuilder: (context, index) {
                return Divider(
                  height: 1,
                );
              },
            ),
          ),
          Container(
            height: SizeList.DRAWER_HEAD_HEIGHT,
            color: Colors.black12,
          )
        ],
      ),
    );
  }

  navPush(BuildContext context, Widget page) {
    Navigator.of(context).pop(); //收起抽屉
    Navigator.push(context, MaterialPageRoute(builder: (context) => page));
  }
}
